Shader "Dan/UI/UI_BottleWave"
{
    Properties
    {
       _Color ("Color", Color) = (0.07843138,0.3921569,0.7843137,1)
        _ColorBG ("ColorBG", Color) = (0.1879892,0.2509804,0.2304512,1)
        _Emission ("Emission", Float ) = 1
        _Progress ("Capacity", Range(0, 1)) = 0.5
        _RadiusSize ("RadiusSize", Range(0, 1)) = 1
        _Outline ("Outline", Range(0, 1)) = 0
        _FlowSpeed ("FlowSpeed", Float ) = 2
        _SmoothWave ("Wave Smooth", Range(0, 1)) = 1
        _Frequency ("Wave Frequency", Float ) = 0.5
        _Range ("Wave Range", Float ) = 16
        _BG_Opacity ("BG_Opacity", Range(0, 1)) = 0.5
        [MaterialToggle] _UseSphereMask ("UseSphereMask", Float ) = 1

    }
    
    SubShader
    {

        Tags { "IgnoreProjector"="True"
            "Queue"="Transparent"
            "RenderType"="Transparent" }
        LOD 100    
        Blend SrcAlpha OneMinusSrcAlpha
        ZWrite Off 
 
        Pass
        {
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            
            #include "UnityCG.cginc"
            #include "../ShaderLibs/UIFX.cginc"
            #include "../ShaderLibs/UVOperator.cginc"
            struct appdata
            {
                float4 vertex : POSITION;
                float2 uv : TEXCOORD0;
            };
            
            struct v2f
            {
                float4 vertex : SV_POSITION;    
                float2 uv : TEXCOORD0;
                
            };

             float4 _Color;
             float _FlowSpeed;
             float _SmoothWave;
             float _Progress;
             float _RadiusSize;
             float4 _ColorBG;
             float _BG_Opacity;
             float _Frequency;
             float _Range;
             float _Emission;
             float _Outline;
             fixed _UseSphereMask;

            v2f vert ( appdata v )
            {
                
                v2f o;
                UNITY_INITIALIZE_OUTPUT(v2f ,o);
                o.vertex = UnityObjectToClipPos(v.vertex);
                
                o.uv = v.uv;        
                return o;
            }
            
            

           

            fixed4 frag (v2f i ) : SV_Target
            {
                float2 uv = i.uv;
                float rect =1-DrawRect01(uv,0.9,0.3);
               
                 
                float circle = length(uv*2-1);//求圆
                float circleSize;//圆的大小
                float outline;//描边
                //返回外描边和控制圆形大小
                DrawOutLine(circleSize,outline,_RadiusSize,_Outline,circle);
                
                float useMask =lerp( 1, circleSize, _UseSphereMask );//启用mask
                //剔除
                clip( useMask- 0.5);
                //画波浪
                float wave = UVWaveLine(uv,_Range,_Frequency,_SmoothWave,_FlowSpeed,_Progress);
                //y方向透明度
                float transparentY =saturate(uv.y*0.5+0.5);
                //背景透明度
                float bgOpacity =wave+(1 - wave)*_BG_Opacity;
                //外描边
                //float outline = circleSize*step((_RadiusSize-_Outline),circle);
                //遮罩
                float circleMask =max(bgOpacity,outline);

                float3 finalColor = lerp(_ColorBG.rgb,_Color.rgb*transparentY*_Emission,circleMask);
                 
                return fixed4(finalColor,1);
                
                
            }
            ENDCG
        }
    }
    
    
    
}
